import { _decorator, Component, Label, Sprite } from 'cc';
import { ResourceManager } from '../framework/ResourceManager';
import { Game } from '../core/Game';
const { ccclass, property } = _decorator;

@ccclass('TvScreenController')
export class TvScreenController extends Component {
  private selfUserHeaderImage: Sprite = null;
  private oppoUserHeaderImage: Sprite = null;
  private selfUserName: Label = null;
  private oppoUserName: Label = null;
  onLoad() {
    this.selfUserHeaderImage = this.node.getChildByName('SelfComponent').getChildByName('UserHeaderImage').getComponent(Sprite);
    this.oppoUserHeaderImage = this.node.getChildByName('OppoComponent').getChildByName('UserHeaderImage').getComponent(Sprite);
    this.selfUserName = this.node.getChildByName('SelfComponent').getChildByName('UserNickName').getComponent(Label);
    this.oppoUserName = this.node.getChildByName('OppoComponent').getChildByName('UserNickName').getComponent(Label);
  }
  start() {
  }
  public update(dt: number) {
    const ssp = ResourceManager.Instance().getImageSpriteFrame(ResourceManager.SelfUserHeaderImage);
    if (ssp) {
      this.selfUserHeaderImage.spriteFrame = ssp;
    }
    const osp = ResourceManager.Instance().getImageSpriteFrame(ResourceManager.OppoUserHeaderImage);
    if (osp) {
      this.oppoUserHeaderImage.spriteFrame = osp;
    }

    this.selfUserName.string = Game.Instance().playUsers[0].userAttribute.showNickName();
    this.oppoUserName.string = Game.Instance().playUsers[1].userAttribute.showNickName();
  }
}

